﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace dal
{
    public class DBHelper
    {
        private static string constr = ConfigurationManager.ConnectionStrings["constr"].ToString();
        /*private static SqlConnection conn = new SqlConnection(constr);*/
        public static SqlDataReader ExecuteReader(string sql, SqlParameter[] paras=null)
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);

            if (paras != null && paras.Length > 0)
                cmd.Parameters.AddRange(paras);
            SqlDataReader red = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            return red;
        }
       /* public static int Exqu(string sql)
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            int r = cmd.ExecuteNonQuery();
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
            return r;
            //
        }*/
    }
}
